pub type __u_char = u8;
pub type __ssize_t = i64;
pub type u_char = __u_char;
pub type ssize_t = __ssize_t;
pub type size_t = u64;
#[no_mangle]
pub extern "C" fn unvis(mut cp: *mut i8, mut c: i8, mut astate: *mut i32, mut flag: i32) -> i32 {
    if flag & 1 != 0 {
        if (unsafe { *astate }) == 5 || (unsafe { *astate }) == 6 {
            (unsafe { *astate = 0 });
            return 1;
        }
        return if (unsafe { *astate }) == 0 { 3
        } else {
            -(1 as i32)
        };
    }
    match unsafe { *astate } {
        0 => {
            (unsafe { *cp = 0 as i8 });
            if c as i32 == '\\' as i32 {
                (unsafe { *astate = 1 });
                return 0;
            }
            (unsafe { *cp = c });
            return 1;
        }
        1 => {
            match c as i32 {
                92 => {
                    (unsafe { *cp = c });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 => {
                    (unsafe { *cp = (c as i32 - '0' as i32) as i8 });
                    (unsafe { *astate = 5 });
                    return 0;
                }
                77 => {
                    (unsafe { *cp = 0o200 as i32 as i8 });
                    (unsafe { *astate = 2 });
                    return 0;
                }
                94 => {
                    (unsafe { *astate = 4 });
                    return 0;
                }
                110 => {
                    (unsafe { *cp = '\n' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                114 => {
                    (unsafe { *cp = '\r' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                98 => {
                    (unsafe { *cp = '\u{8}' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                97 => {
                    (unsafe { *cp = '\u{7}' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                118 => {
                    (unsafe { *cp = '\u{b}' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                116 => {
                    (unsafe { *cp = '\t' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                102 => {
                    (unsafe { *cp = '\u{c}' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                115 => {
                    (unsafe { *cp = ' ' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                69 => {
                    (unsafe { *cp = '\u{1b}' as i32 as i8 });
                    (unsafe { *astate = 0 });
                    return 1;
                }
                10 => {
                    (unsafe { *astate = 0 });
                    return 3;
                }
                36 => {
                    (unsafe { *astate = 0 });
                    return 3;
                }
                _ => {}
            }
            (unsafe { *astate = 0 });
            return -(1 as i32);
        }
        2 => {
            if c as i32 == '-' as i32 {
                (unsafe { *astate = 3 });
            } else if c as i32 == '^' as i32 {
                (unsafe { *astate = 4 });
            } else {
                (unsafe { *astate = 0 });
                return -(1 as i32);
            }
            return 0;
        }
        3 => {
            (unsafe { *astate = 0 });
            (unsafe { *cp = (*cp as i32 | c as i32) as i8 });
            return 1;
        }
        4 => {
            if c as i32 == '?' as i32 {
                (unsafe { *cp = (*cp as i32 | 0o177 as i32) as i8 });
            } else {
                (unsafe { *cp = (*cp as i32 | c as i32 & 0o37 as i32) as i8 });
            }
            (unsafe { *astate = 0 });
            return 1;
        }
        5 => {
            if c as u_char as i32 >= '0' as i32 && c as u_char as i32 <= '7' as i32 {
                (unsafe { *cp = (((*cp as i32) << 3) + (c as i32 - '0' as i32)) as i8 });
                (unsafe { *astate = 6 });
                return 0;
            }
            (unsafe { *astate = 0 });
            return 2;
        }
        6 => {
            (unsafe { *astate = 0 });
            if c as u_char as i32 >= '0' as i32 && c as u_char as i32 <= '7' as i32 {
                (unsafe { *cp = (((*cp as i32) << 3) + (c as i32 - '0' as i32)) as i8 });
                return 1;
            }
            return 2;
        }
        _ => {
            (unsafe { *astate = 0 });
            return -(1 as i32);
        }
    };
}
#[no_mangle]
pub extern "C" fn strunvis(mut dst: *mut i8, mut src: *const i8) -> i32 {
    let mut c: i8 = 0;
    let mut start: *mut i8 = dst;
    let mut state: i32 = 0;
    loop {
        let fresh0 = src;
        src = unsafe { src.offset(1) };
        c = unsafe { *fresh0 };
        if c == 0 {
            break;
        }
        loop {
            match unvis(dst, c, &mut state, 0) {
                1 => {
                    dst = unsafe { dst.offset(1) };
                    break;
                }
                2 => {
                    dst = unsafe { dst.offset(1) };
                }
                0 | 3 => {
                    break;
                }
                _ => {
                    (unsafe { *dst = '\0' as i32 as i8 });
                    return -(1 as i32);
                }
            }
        }
    }
    if unvis(dst, c, &mut state, 1) == 1 {
        dst = unsafe { dst.offset(1) };
    }
    (unsafe { *dst = '\0' as i32 as i8 });
    return (unsafe { dst.offset_from(start) }) as i64 as i32;
}
#[no_mangle]
pub extern "C" fn strnunvis(mut dst: *mut i8, mut src: *const i8, mut sz: size_t) -> ssize_t {
    let mut c: i8 = 0;
    let mut p: i8 = 0;
    let mut start: *mut i8 = dst;
    let mut end: *mut i8 = unsafe { dst.offset(sz as isize).offset(-(1 as i32 as isize)) };
    let mut state: i32 = 0;
    if sz > 0 as u64 {
        (unsafe { *end = '\0' as i32 as i8 });
    }
    loop {
        let fresh1 = src;
        src = unsafe { src.offset(1) };
        c = unsafe { *fresh1 };
        if c == 0 {
            break;
        }
        loop {
            match unvis(&mut p, c, &mut state, 0) {
                1 => {
                    if dst < end {
                        (unsafe { *dst = p });
                    }
                    dst = unsafe { dst.offset(1) };
                    break;
                }
                2 => {
                    if dst < end {
                        (unsafe { *dst = p });
                    }
                    dst = unsafe { dst.offset(1) };
                }
                0 | 3 => {
                    break;
                }
                _ => {
                    if dst <= end {
                        (unsafe { *dst = '\0' as i32 as i8 });
                    }
                    return -(1 as i32) as ssize_t;
                }
            }
        }
    }
    if unvis(&mut p, c, &mut state, 1) == 1 {
        if dst < end {
            (unsafe { *dst = p });
        }
        dst = unsafe { dst.offset(1) };
    }
    if dst <= end {
        (unsafe { *dst = '\0' as i32 as i8 });
    }
    return (unsafe { dst.offset_from(start) }) as i64;
}
